//-----------------------------------------------------------------------//
// HELPERS
//
// These are functions that are called from the mixins to setup stuff
// like duration, fill-mode etc.
//
// Credit to @jackilyn who first drafted these over at
// https://github.com/jackilyn/animate.scss
//-----------------------------------------------------------------------//

@mixin animation($animations...) {
	@include prefixer(animation, $animations, webkit moz spec);
}

//-----------------------------------------------------------------------//
// @animation-name	Sets the animation name. Required
//-----------------------------------------------------------------------//
@mixin animation-name($animation-name) {
	@include prefixer(animation-name, $animation-name, $prefixes);
}

//-----------------------------------------------------------------------//
// @duration		Specifies how many seconds or milliseconds an animation takes
//							to complete one cycle. Default 0
//-----------------------------------------------------------------------//
@mixin duration($duration: 1s) {
	@include prefixer(animation-duration, $duration, $prefixes);
}

//-----------------------------------------------------------------------//
// @delay				Specifies when the animation will start. Default 0
//-----------------------------------------------------------------------//
@mixin delay($delay: .2s) {
	@include prefixer(animation-delay, $delay, $prefixes);
}

//-----------------------------------------------------------------------//
// @function		Describes how the animation will progress over one cycle of its
//							duration. Default "ease"
//-----------------------------------------------------------------------//
@mixin function($function: ease) {
	@include prefixer(animation-timing-function, $function, $prefixes);
}

//-----------------------------------------------------------------------//
// @count				Specifies the number of times an animation is played. Default 1
//							This basically isn't supported anywhere right now but its still
//							in here for future use.
//-----------------------------------------------------------------------//
@mixin count($count: 1) {
	animation-iteration-count: 1;
}

//-----------------------------------------------------------------------//
// @fill-mode		Specifies whether the effects of an animation are apparent
//							before the animation starts and after it ends.
//-----------------------------------------------------------------------//
@mixin fill-mode($fill: both) {
	@include prefixer(animation-fill-mode, $fill, $prefixes);
}

//-----------------------------------------------------------------------//
// @visibility	Determines whether or not a transformed element is visible when
// 							it is not facing the screen.
//-----------------------------------------------------------------------//
@mixin visibility($visibility: hidden) {
	@include prefixer(animation-backface-visibility, $visibility, $prefixes);
}

//-----------------------------------------------------------------------//
// @transform	Sets the tranform property
//-----------------------------------------------------------------------//
@mixin transform($property: none) {
	@include prefixer(transform, $property, $prefixes);
}

//-----------------------------------------------------------------------//
// @transform-origin	Sets the origin for 3d-animations
//-----------------------------------------------------------------------//
@mixin transform-origin($transform-origin: center center) {
	@include prefixer(transform-origin, $transform-origin, $prefixes);
}

//-----------------------------------------------------------------------//
// @transform-style
//-----------------------------------------------------------------------//
@mixin transform-style($transform-style: flat) {
	@include prefixer(transform-style, $transform-style, $prefixes);
}

//-----------------------------------------------------------------------//
// @keyframes
//-----------------------------------------------------------------------//

@mixin keyframes($name) {
	$original-prefix-for-webkit:		$prefix-for-webkit;
	$original-prefix-for-mozilla:		$prefix-for-mozilla;
	$original-prefix-for-microsoft:	$prefix-for-microsoft;
	$original-prefix-for-opera:			$prefix-for-opera;
	$original-prefix-for-spec:			$prefix-for-spec;

	@if $original-prefix-for-webkit {
		@include disable-prefix-for-all();
		$prefix-for-webkit: true !global;
		@-webkit-keyframes #{$name} {
			@content;
		}
	}
	@if $original-prefix-for-mozilla {
		@include disable-prefix-for-all();
		$prefix-for-mozilla: true !global;
		@-moz-keyframes #{$name} {
			@content;
		}
	}
	@if $original-prefix-for-opera {
		@include disable-prefix-for-all();
		$prefix-for-opera: true !global;
		@-o-keyframes #{$name} {
			@content;
		}
	}

	@if $original-prefix-for-spec {
		@include disable-prefix-for-all();
		// Newish Blink browsers recognize the unprefixed @keyframe but still needs the -webkit prefix for transitions
		$prefix-for-webkit: true !global;
		$prefix-for-spec: true !global;
		@keyframes #{$name} {
			@content;
		}
	}

	$prefix-for-webkit:			$original-prefix-for-webkit !global;
	$prefix-for-mozilla:		$original-prefix-for-mozilla !global;
	$prefix-for-microsoft:	$original-prefix-for-microsoft !global;
	$prefix-for-opera:			$original-prefix-for-opera !global;
	$prefix-for-spec:				$original-prefix-for-spec !global;
}

@mixin prefixer ($property, $value, $prefixes) {
	@each $prefix in $prefixes {
		@if $prefix == webkit {
			@if $prefix-for-webkit {
				-webkit-#{$property}: $value;
			}
		}
		@else if $prefix == moz {
			@if $prefix-for-mozilla {
				-moz-#{$property}: $value;
			}
		}
		@else if $prefix == ms {
			@if $prefix-for-microsoft {
				-ms-#{$property}: $value;
			}
		}
		@else if $prefix == o {
			@if $prefix-for-opera {
				-o-#{$property}: $value;
			}
		}
		@else if $prefix == spec {
			@if $prefix-for-spec {
				#{$property}: $value;
			}
		}
		@else  {
			@warn "Unrecognized prefix: #{$prefix}";
		}
	}
}

@mixin disable-prefix-for-all() {
	$prefix-for-webkit:    false !global;
	$prefix-for-mozilla:   false !global;
	$prefix-for-microsoft: false !global;
	$prefix-for-opera:     false !global;
	$prefix-for-spec:      false !global;
}